<?php
if ( !$_SESSION['name'] ) {
    $str = 'a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z';
    $arr = explode( '-', $str );
    $len = mt_rand( 1, 26 );
    //名字的长度
    $index = array_rand( $arr, $len );
    //随机取$len个索引, 即名字长度
    $name = '';
    foreach ( $index as $value ) {
        $name .= $arr[$value];
    }
    $_SESSION['name'] = $name;
}
echo "用户名：" . $_SESSION['name'];
echo '<br>';
echo 'id：' . session_id();
?>
<br>
<a href="show.php">去获取用户名</a>